package br.com.linhadotempo.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import br.com.taimlain.modelo.Auth;

public class Cifras {

	public static Auth cifrarEsse(Auth auth) {

		try {
			auth.setUsername(Cifras.criptografarEssa(auth.getUsername()));
			auth.setPassword(Cifras.criptografarEssa(auth.getPassword()));
		} catch (Exception e) {
			e.printStackTrace();
			Mensagens.getInstance().setError(e.getCause().getMessage());
		}
		return auth;
	}

	public static String criptografarEssa(String palavra) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			BigInteger hash = new BigInteger(1, md.digest(palavra.getBytes()));
			return hash.toString(16);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			Mensagens.getInstance().setError(e.getCause().getMessage());
			return null;
		}

	}
}
